package com.dyz.leetcode._20_dynamicProgramming._746;

import java.util.Arrays;

public class _756_minCostClimbingStairs01 {
    public int minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int [] memo = new int[n+1];
        Arrays.fill(memo, -1);

        return dfs(cost, n, memo);

    }

    private int dfs(int[] cost, int i, int[] memo){
        if(i==0 || i==1){
            return 0;
        }
        if(memo[i]!=-1){return memo[i];}
        //左子树
        int left = dfs(cost, i-1, memo);
        //右
        int right = dfs(cost, i-2, memo);
        memo[i] = Math.min(left+cost[i-1], right+cost[i-2]);
        return memo[i];
    }
}
